package org.lion.jingbeifang_interviewquestions.calculatePrice.service;

import org.lion.jingbeifang_interviewquestions.calculatePrice.entity.Goods;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 题目1:无折扣正常计算价格
 */
public class CommonCalculate {


    public BigDecimal calculateGoodsPrice(List<Goods> goodsList){
        BigDecimal totalPrice = BigDecimal.ZERO;

        for (Goods goods : goodsList){
            BigDecimal price = goods.getGoodsItem().getPrice();
            if (price != null){
                BigDecimal itemPrice = price.multiply(BigDecimal.valueOf(goods.getWeight())).multiply(BigDecimal.valueOf(goods.getDiscount().getDiscount()));
                totalPrice = totalPrice.add(itemPrice);
            }
        }
        return totalPrice;
    }

}
